import paramiko,os,time
import configparser
from batch_server_manage.conf import settings
class Servermanage(object):
    def run(self):
        while True:
            print('''
            1.显示目前所有主机信息
            2.可批量执行命令
            3.发送文件
            
            ''')
            try:
                choice = int(input("please choice operate you want: ").strip())
            except Exception:
                print("invalid data  you have input")
                exit()

            operate = {1:"server_info",2:"execute_command",3:"send_file"}
            if hasattr(self,operate[choice]):
                func = getattr(self,operate[choice])
                func()



    def server_info(self):
        cf = configparser.ConfigParser()
        cf.read("%s/conf/servergroup.conf"%(settings.BASEDIR))
        secs = cf.sections()
        for i in secs:
            print("主机组:",i)
            for a in cf.options(i):
                print(a,)
                print(cf.get(i,a)))
                for host in (cf.get(i,a)):
                    print(host)
                    # for kes in key:
                #     print(key[kes])


    def execute_command(self):
        pass
    def send_file(self):
        pass

manage = Servermanage()
manage.run()